package com.pac.bean.course;


import com.alibaba.fastjson.JSON;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * bean 教程Item
 * Created by huang on 15-4-22.
 */
public class CourseItem {
    private String id;
    private String name;
    private List<CourseChildItem> child;
    private String ico;

    /**
     * 从json中获取list
     * @param json 网络下载的json
     * @return 课程页的list
     */
    public static List<CourseItem> getListFromJsonStr(String json) {
        try {
            JSONObject jsonObject = new JSONObject(json);
            if ("成功".equals(jsonObject.optString("msg"))) {
                return JSON.parseArray(jsonObject.optString("list"), CourseItem.class);
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
        return null;
    }

    /**
     * 获取该分组下的所有子分类的名字
     * @return 子分类名字
     */
    public String getChildrenNames(){
        String str = "";
        for(CourseChildItem c:this.child){
            str+=c.getName()+",";
        }
        return str;
    }
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<CourseChildItem> getChild() {
        return child;
    }

    public void setChild(List<CourseChildItem> child) {
        this.child = child;
    }

    public String getIco() {
        return ico;
    }

    public void setIco(String ico) {
        this.ico = ico;
    }


}
